﻿namespace NEvoWeb.Modules.NB_Store
{
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Web;
    using System.Xml;

    public abstract class FileProvider : IHttpHandler
    {
        protected FileProvider()
        {
        }

        public void ProcessRequest(HttpContext context)
        {
            string str2 = SharedFunctions.getURLParam(context, "key");
            string expression = SharedFunctions.getURLParam(context, "did");
            string str3 = SharedFunctions.getURLParam(context, "PortalID");
            if (Versioned.IsNumeric(expression))
            {
                NB_Store_OrderDetailsInfo orderDetail = new OrderController().GetOrderDetail(Conversions.ToInteger(expression));
                if (orderDetail.CartXMLInfo != "")
                {
                    string innerText;
                    XmlDataDocument document = new XmlDataDocument();
                    document.LoadXml(orderDetail.CartXMLInfo);
                    try
                    {
                        if (str2 == "")
                        {
                            innerText = document.SelectSingleNode("root/fuupload").InnerText;
                        }
                        else
                        {
                            innerText = document.SelectSingleNode("root/" + str2).InnerText;
                        }
                    }
                    catch (Exception exception1)
                    {
                        ProjectData.SetProjectError(exception1);
                        Exception exception = exception1;
                        innerText = "";
                        ProjectData.ClearProjectError();
                    }
                    if (innerText != "")
                    {
                        string str6 = Strings.Right(innerText, 3);
                        string str7 = context.Request.Headers["User-Agent"];
                        if (str7.Contains("MSIE 7.0") | str7.Contains("MSIE 8.0"))
                        {
                            context.Response.AppendHeader("content-disposition", "attachment; filename=\"" + Strings.Replace(orderDetail.ItemDesc, " ", "_", 1, -1, CompareMethod.Binary) + "." + str6 + "\"");
                        }
                        else
                        {
                            context.Response.AppendHeader("content-disposition", "attachment; filename=\"" + HttpUtility.UrlDecode(Strings.Replace(orderDetail.ItemDesc, " ", "_", 1, -1, CompareMethod.Binary)) + "." + str6 + "\"");
                        }
                        context.Response.ContentType = "application/octet-stream";
                        context.Response.WriteFile(innerText);
                        context.Response.End();
                    }
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

       
    }
}

